﻿using Awsc.DataAcquisitionSys.Core.Common.Extensions;
using Awsc.DataAcquisitionSys.Core.DataAcquisition;
using Awsc.DataAcquisitionSys.Core.Model.Config;
using Awsc.DataAcquisitionSys.Core.Models.ServiceModels;

namespace Awsc.DataAcquisitionSys.Core.Services.DataAcquisition.DataCollectors.Sensors
{
    public class WeighSensor : Sensor
    {
        private readonly RegisterConfig config;
        private readonly WeighSensorConfig weighSensorConfig;
        public WeighSensor(AbstractSensorDataCollectionContext abstractSensorDataCollectionContext)
        {
            config = abstractSensorDataCollectionContext.SensorConfig as RegisterConfig;
            weighSensorConfig = config.GetAdditionConfig<WeighSensorConfig>();
        }



        protected override void CalculateValue()
        {
            var weighSensorA = GlobalDeviceManager.Instance.GetSensorValue("支腿1");
            var weighSensorB = GlobalDeviceManager.Instance.GetSensorValue("支腿2");
            var weighSensorC = GlobalDeviceManager.Instance.GetSensorValue("支腿3");
            var weighSensorD = GlobalDeviceManager.Instance.GetSensorValue("支腿4");

            if (weighSensorA.Value != null && weighSensorB.Value != null && weighSensorC.Value != null && weighSensorD.Value != null)
            {
                //相关传感器全部正常工作，则进行计算
                var mesureValue = weighSensorA.ToDouble() + weighSensorB.ToDouble() + weighSensorC.ToDouble() + weighSensorD.ToDouble();
                OutputValue = mesureValue;
                CurrentValue = mesureValue;
                Status = DevStatus.S_OK;
            }
            else
            {
                Status = DevStatus.S_UNKNOWN;
            }
        }
    }
}
